package com.lagou.blog.controller;

import com.github.pagehelper.PageInfo;
import com.lagou.blog.entity.Article;
import com.lagou.blog.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.Banner;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller

public class BlogController {
    @Autowired
    private ArticleService articleService;
    @RequestMapping("/")
    public ModelAndView toIndex(@RequestParam(value="pageNum",defaultValue = "1") Integer pageNum,
                                @RequestParam(value="pageSize",defaultValue = "2") Integer pageSize){
        ModelAndView modelAndView = new ModelAndView("client/index");
        PageInfo<Article> all = articleService.findAll(pageNum, pageSize);
        List<Article> articleList = all.getList();
        modelAndView.addObject("articleList",articleList);
        int prePage = all.getPrePage();
        int nextPage = all.getNextPage();
        int pages = all.getPages();
        modelAndView.addObject("prePage",prePage);
        modelAndView.addObject("nextPage",nextPage);
        modelAndView.addObject("pages",pages);
        return modelAndView;
    }

}
